home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MLS.C < prev    next >
C/C++ Source or Header  |  1991-04-05  |  4KB  |  136 lines

  1. /*  mls.c        -- do an 'ls -lR' of a Minix file system */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved. */
  3. /*  $Header: MLS.C_V 1.5 91/04/05 15:51:35 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <ctype.h>
  7. #include    <stdlib.h>
  8. #include    <string.h>
  9. #include    "mfs.h"
  10. #include    "dev.h"
  11.  
  12. DEVINIT
  13. READ_BLOCK
  14. SHOW_DIR
  15.  
  16. BOOL    Nonly ;
  17.  
  18.  
  19. /*==================================================================*/
  20. main (argc, argv)
  21. int     argc ;
  22. char    *argv[] ;
  23. {
  24.     int     drive ;
  25.     char    drid = 'A' ;
  26.     char    *dp = DRIVES ;
  27.  
  28.     byte    buf[BLOCK_SIZE] ;
  29.     int     blkno ;
  30.     struct super_block  sblk ;
  31.  
  32.     struct inode    *iarea, *ip ;
  33.     int     inode_blkno ;
  34.     int     inode_blkct ;
  35.     int     inode_count ;
  36.  
  37.     struct directory    *darea ;
  38.     struct devdata      *ddata ;
  39.  
  40.     int     i, j, k, n ;
  41.  
  42.     printf ("**** Displays directories in a Minix file system ****\n") ;
  43.     printf ("\n") ;
  44.  
  45. /*  Does he want help?
  46.  */
  47.     if ((argc >= 2) && (argv[1][0] == '-') && (argv[1][1] == '?'))
  48.     {
  49. printf ("Copyright 1988,1991 Steven W. Harrold - All rights reserved\n") ;
  50.         printf ("Version %s\n", VERSION) ;
  51.         printf ("Usage:   %s  [-l] [drid]\n", argv[0]) ;
  52.         printf ("'-l' causes long form of directory details to be listed\n") ;
  53.         printf ("'drid' is a letter from the set [a-z], default: 'a'\n") ;
  54.         exit (0) ;
  55.     }
  56.  
  57. /*  Get the option flag
  58.  */
  59.     if ((argc >= 2) && (argv[1][0] == '-') && (argv[1][1] == 'l'))
  60.     {
  61.         Nonly = FALSE ;
  62.         argc-- ;
  63.         argv++ ;
  64.     }
  65.     else
  66.         Nonly = TRUE ;
  67.  
  68. /*  Fetch the drive identifier
  69.  */
  70.     if (argc >= 2)
  71.     {
  72.         drid = toupper(argv[1][0]) ;
  73.         if ((drid < 'A') || (drid > 'Z'))
  74.             drid = 'A' ;
  75.     }
  76.     drive = strchr (dp, drid) - dp ;
  77.     ddata = devinit (drive, 0) ;
  78.     if (!ddata)
  79.     {
  80.         printf ("Cannot initialize device 0x%02X, Dstatus=%d\n",
  81.                 drive, Dstatus) ;
  82.         exit (2) ;
  83.     }
  84.  
  85. /*  The super block
  86.  */
  87.     blkno = SUPER_BLOCK ;
  88.     read_block (buf, blkno, ddata) ;
  89.     memcpy (&sblk, buf, sizeof(sblk)) ;
  90.  
  91.     if ((sblk.s_magic != SUPER_MAGIC)   ||
  92.         (sblk.s_ninodes < 1)            ||
  93.         (sblk.s_nzones < 1)             ||
  94.         (sblk.s_imap_blocks < 1)        ||
  95.         (sblk.s_zmap_blocks < 1)        )
  96.     {
  97.         printf ("+++++++++++++++++++++++++++++++++++++++++++++++\n") ;
  98.         printf ("++++++++ THIS IS NOT A PROPER MINIX DISK ++++++\n") ;
  99.         printf ("+++++++++++++++++++++++++++++++++++++++++++++++\n") ;
  100.         exit (2) ;
  101.     }
  102.  
  103. /*  The i-node blocks
  104.  */
  105.     inode_blkno = SUPER_BLOCK + sblk.s_imap_blocks +
  106.                                 sblk.s_zmap_blocks + 1 ;
  107.     inode_blkct = sblk.s_ninodes * sizeof(struct inode) + (BLOCK_SIZE-1) ;
  108.     inode_blkct /= BLOCK_SIZE ;
  109.     inode_count = inode_blkct * sizeof(struct inode) ;
  110.  
  111.     iarea = calloc (inode_count+1, sizeof(struct inode)) ;
  112.     if (!iarea)
  113.         exit(3) ;
  114.  
  115.     ip = iarea + 1 ;
  116.     blkno = inode_blkno ;
  117.     j = BLOCK_SIZE / sizeof(struct inode) ;
  118.  
  119.     for (i=1; i<=inode_blkct; i++, ip += j, blkno++)
  120.         read_block (ip, blkno, ddata) ;
  121.  
  122.  
  123. /*  Finally, the directories
  124.  */
  125.     ip = iarea + ROOT_INODE ;           /* start with root */
  126.     show_dir(ddata, iarea, ip, "/") ;   /* recursively print */
  127.  
  128. /*  Clean up
  129.  */
  130.     free (iarea) ;
  131.  
  132. } /* main() */
  133.  
  134.  
  135. /*---eof---*/
  136.